﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO;
using System.Runtime.InteropServices;

namespace FWMS
{

    public partial class Form_rukuguanli : Form
    {
        [DllImport("kernel32.dll")]
        public static extern IntPtr _lopen(string lpPathName, int iReadWrite);
        [DllImport("kernel32.dll")]
        public static extern void fclose(IntPtr hObject);
        [DllImport("kernel32.dll")]
        public static extern bool CloseHandle(IntPtr hObject);
        public const int OF_READWRITE = 2;
        public const int OF_SHARE_DENY_NONE = 0x40;
        public readonly IntPtr HFILE_ERROR = new IntPtr(-1);
        //入库管理
        public Form_rukuguanli()
        {
            InitializeComponent();
        }
        //类型选择
        private static int rukustyle;
        //库存管理
        private static bool kucunflag;
        //查询结果的数据
        public object[,] Selectresult;
        //条件查询结果的数据
        public object[,] ConditionSelectresult;
        //EXCEL明细
        private static string sheet4name = "insert";
        //FORM初始化
        private void Form_rukuguanli_Load(object sender, EventArgs e)
        {
            COMMAND.CommandBean.rukuflag = true;
            COMMAND.CommandBean.chukuflag = false;
            kucunflag = false;
            rukustyle = 0;
            ruku_yuancailiao_init();
        }
        //原料导出EXCEL按钮按下
        private void bt_importexcel_Click(object sender, EventArgs e)
        {
            Bean.Rukuguanli_yuancailiaoBean bean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
            //导出数据前CHECK
            if (!ruku_infocheck(bean, "1"))
            {
                return;
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string path2 = "";
            saveFileDialog1.Filter = "EXCEL files(*.xls)|*.xls";
            saveFileDialog1.FilterIndex = 1;
            saveFileDialog1.RestoreDirectory = true;
            //保存EXCEL
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                path2 = saveFileDialog1.FileName.ToString();
            }
            else
            {
                return;
            }
            saveFileDialog1.Dispose();

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            if (File.Exists(path2))
            {
                IntPtr vHandle = _lopen(path2, OF_READWRITE | OF_SHARE_DENY_NONE);
                if (vHandle == HFILE_ERROR)
                {
                    MessageBox.Show("该文件已经打开，请关闭后重新导出！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    CloseHandle(vHandle);
                    File.Delete(path2);
                }
            }
            //System.IO.File.Copy(path + "\\原料入库MODEL.xls", path2);
            /*
            CloseHandle(vHandle);
            MessageBox.Show("没有被占用！");
            */
            COMMAND.CommandMicrosoftExcel importexcel = new FWMS.COMMAND.CommandMicrosoftExcel();
            importexcel.Open(path + "\\原料入库MODEL.xls");
            //入库基本信息导出
            string date = bean.Ruku_daohuo.ToString().Substring(0, 4) + "年" +
                    bean.Ruku_daohuo.ToString().Substring(4, 2) + "月" +
                    bean.Ruku_daohuo.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 1, 1, "发货" + date);
            date = bean.Ruku_yanshou.ToString().Substring(0, 4) + "年" +
                    bean.Ruku_yanshou.ToString().Substring(4, 2) + "月" +
                    bean.Ruku_yanshou.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 2, 1, "验收" + date);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 3, 1, bean.Ruku_no);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 4, 1, "发货单位:" + bean.Ruku_fahuodanwei);
            int k = 0;
            //数据集合导出
            for (int i = 0; i < this.dataGridView_yuanliaoinfo.Rows.Count - 1; i++)
            {
                if (!"".Equals(COMMAND.Command.toString(this.dataGridView_yuanliaoinfo.Rows[i].Cells[0].Value).Trim()))
                {
                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 1, this.dataGridView_yuanliaoinfo.Rows[i].Cells[0].Value.ToString().Trim());
                    k++;
                    if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[1].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, this.dataGridView_yuanliaoinfo.Rows[i].Cells[1].Value.ToString().Trim());
                    }

                    if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[2].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, this.dataGridView_yuanliaoinfo.Rows[i].Cells[2].Value.ToString().Trim());
                    }

                    if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[3].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, this.dataGridView_yuanliaoinfo.Rows[i].Cells[3].Value.ToString().Trim());
                    }

                    if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[4].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, this.dataGridView_yuanliaoinfo.Rows[i].Cells[4].Value.ToString().Trim());
                    }

                    if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[5].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, this.dataGridView_yuanliaoinfo.Rows[i].Cells[5].Value.ToString().Trim());
                    }
                    if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[6].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, this.dataGridView_yuanliaoinfo.Rows[i].Cells[6].Value.ToString().Trim());
                    }
                }
                else
                {
                    continue;
                }

            }
            if (k < 12)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("原料入库1"), 24, 45);
            }
            else if (k > 22 && k < 34)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("原料入库2"), 24, 45);
            }
            else if (k > 44 && k < 56)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("原料入库3"), 24, 45);
            }
            importexcel.SaveAs(path2);
            importexcel.Close();
            MessageBox.Show("导出EXCEL成功，请注意保存当前数据！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //调味料导出EXCEL按钮按下
        private void bt_ruku_tiaoweiliao_importexcel_Click(object sender, EventArgs e)
        {
            Bean.Rukuguanli_tiaoweiliaoBean bean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
            //导出数据前CHECK
            if (!ruku_infocheck(bean, "1"))
            {
                return;
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string path2 = "";
            saveFileDialog1.Filter = "EXCEL files(*.xls)|*.xls";
            saveFileDialog1.FilterIndex = 1;
            saveFileDialog1.RestoreDirectory = true;
            //保存EXCEL
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                path2 = saveFileDialog1.FileName.ToString();
            }
            else
            {
                return;
            }
            saveFileDialog1.Dispose();

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            if (File.Exists(path2))
            {
                IntPtr vHandle = _lopen(path2, OF_READWRITE | OF_SHARE_DENY_NONE);
                if (vHandle == HFILE_ERROR)
                {
                    MessageBox.Show("选择文件己打开请关闭后再导入");
                    return;
                }
                else
                {
                    CloseHandle(vHandle);
                    File.Delete(path2);
                }
            }
            //System.IO.File.Copy(path + "\\原料入库MODEL.xls", path2);
            /*
            CloseHandle(vHandle);
            MessageBox.Show("没有被占用！");
            */
            COMMAND.CommandMicrosoftExcel importexcel = new FWMS.COMMAND.CommandMicrosoftExcel();
            importexcel.Open(path + "\\物料入库MODEL.xls");
            //入库基本信息导出
            string date = bean.Ruku_daohuo.ToString().Substring(0, 4) + "年" +
                          bean.Ruku_daohuo.ToString().Substring(4, 2) + "月" +
                          bean.Ruku_daohuo.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 1, 1, "发货" + date);
            date = bean.Ruku_yanshou.ToString().Substring(0, 4) + "年" +
            bean.Ruku_yanshou.ToString().Substring(4, 2) + "月" +
            bean.Ruku_yanshou.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 2, 1, "验收" + date);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 3, 1, bean.Ruku_no);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 4, 1, "发货单位:" + bean.Ruku_fahuodanwei);
            //数据集合导出
            int k = 0;
            for (int i = 0; i < this.dataGridView_ruku_tiaoweiliao.Rows.Count - 1; i++)
            {
                if (!"".Equals(COMMAND.Command.toString(this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[0].Value).Trim()))
                {
                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 1, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[0].Value.ToString().Trim());
                    k++;
                    if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[1].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[1].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[2].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[2].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[3].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[3].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[4].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[4].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[5].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[5].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[6].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[6].Value.ToString().Trim());
                    }
                }
                else
                {
                    continue;
                }
            }
            if (k < 12)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("物料入库1"), 24, 45);
            }
            else if (k > 22 && k < 34)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("物料入库2"), 24, 45);
            }
            else if (k > 44 && k < 56)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("物料入库3"), 24, 45);
            }
            importexcel.SaveAs(path2);
            importexcel.Close();
            MessageBox.Show("导出EXCEL成功，请注意保存当前数据！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //辅料导出EXCEL按钮按下
        private void bt_ruku_fuliao_importexcel_Click(object sender, EventArgs e)
        {
            Bean.Rukuguanli_fuliaoBean bean = new FWMS.Bean.Rukuguanli_fuliaoBean();
            //导出数据前CHECK
            if (!ruku_infocheck(bean, "1"))
            {
                return;
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string path2 = "";
            saveFileDialog1.Filter = "EXCEL files(*.xls)|*.xls";
            saveFileDialog1.FilterIndex = 1;
            saveFileDialog1.RestoreDirectory = true;
            //保存EXCEL
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                path2 = saveFileDialog1.FileName.ToString();
            }
            else
            {
                return;
            }
            saveFileDialog1.Dispose();

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            if (File.Exists(path2))
            {
                IntPtr vHandle = _lopen(path2, OF_READWRITE | OF_SHARE_DENY_NONE);
                if (vHandle == HFILE_ERROR)
                {
                    MessageBox.Show("该文件已经打开，请关闭后重新导出！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    CloseHandle(vHandle);
                    File.Delete(path2);
                }
            }
            //System.IO.File.Copy(path + "\\原料入库MODEL.xls", path2);
            /*
            CloseHandle(vHandle);
            MessageBox.Show("没有被占用！");
            */
            COMMAND.CommandMicrosoftExcel importexcel = new FWMS.COMMAND.CommandMicrosoftExcel();
            importexcel.Open(path + "\\物料入库MODEL.xls");
            //入库基本信息导出                      w
            string date = bean.Ruku_daohuo.ToString().Substring(0, 4) + "年" + bean.Ruku_daohuo.ToString().Substring(4, 2) + "月" + bean.Ruku_daohuo.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 1, 1, "发货" + date);
            date = bean.Ruku_yanshou.ToString().Substring(0, 4) + "年" + bean.Ruku_yanshou.ToString().Substring(4, 2) + "月" + bean.Ruku_yanshou.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 2, 1, "验收" + date);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 3, 1, "№:" + bean.Ruku_no);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 4, 1, "发货单位:" + bean.Ruku_fahuodanwei);
            //数据集合导出
            int k = 0;
            for (int i = 0; i < this.dataGridView_ruku_fuliao.Rows.Count - 1; i++)
            {
                if (!"".Equals(COMMAND.Command.toString(this.dataGridView_ruku_fuliao.Rows[i].Cells[0].Value).Trim()))
                {
                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 1, this.dataGridView_ruku_fuliao.Rows[i].Cells[0].Value.ToString().Trim());
                    k++;
                    if (this.dataGridView_ruku_fuliao.Rows[i].Cells[1].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, this.dataGridView_ruku_fuliao.Rows[i].Cells[1].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_fuliao.Rows[i].Cells[2].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, this.dataGridView_ruku_fuliao.Rows[i].Cells[2].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_fuliao.Rows[i].Cells[3].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, this.dataGridView_ruku_fuliao.Rows[i].Cells[3].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_fuliao.Rows[i].Cells[4].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, this.dataGridView_ruku_fuliao.Rows[i].Cells[4].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_fuliao.Rows[i].Cells[5].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, this.dataGridView_ruku_fuliao.Rows[i].Cells[5].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_fuliao.Rows[i].Cells[6].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, this.dataGridView_ruku_fuliao.Rows[i].Cells[6].Value.ToString().Trim());
                    }
                }
                else
                {
                    continue;
                }

            }
            if (k < 12)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("物料入库1"), 24, 45);
            }
            else if (k > 22 && k < 34)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("物料入库2"), 24, 45);
            }
            else if (k > 44 && k < 56)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("物料入库3"), 24, 45);
            }
            importexcel.SaveAs(path2);
            importexcel.Close();
            MessageBox.Show("导出EXCEL成功，请注意保存当前数据！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //成品导出EXCEL按钮按下
        private void bt_ruku_chanpin_importexcel_Click(object sender, EventArgs e)
        {
            Bean.Rukuguanli_chanpinBean bean = new FWMS.Bean.Rukuguanli_chanpinBean();
            //导出数据前CHECK
            if (!ruku_infocheck(bean, "1"))
            {
                return;
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string path2 = "";
            saveFileDialog1.Filter = "EXCEL files(*.xls)|*.xls";
            saveFileDialog1.FilterIndex = 1;
            saveFileDialog1.RestoreDirectory = true;
            //保存EXCEL
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                path2 = saveFileDialog1.FileName.ToString();
            }
            else
            {
                return;
            }
            saveFileDialog1.Dispose();

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            if (File.Exists(path2))
            {
                IntPtr vHandle = _lopen(path2, OF_READWRITE | OF_SHARE_DENY_NONE);
                if (vHandle == HFILE_ERROR)
                {
                    MessageBox.Show("选择文件己打开请关闭后再导入");
                    return;
                }
                else
                {
                    CloseHandle(vHandle);
                    File.Delete(path2);
                }
            }
            //System.IO.File.Copy(path + "\\原料入库MODEL.xls", path2);
            /*
            CloseHandle(vHandle);
            MessageBox.Show("没有被占用！");
            */
            COMMAND.CommandMicrosoftExcel importexcel = new FWMS.COMMAND.CommandMicrosoftExcel();
            importexcel.Open(path + "\\成品入库MODEL.xls");
            //入库基本信息导出  
            string nowdate = DateTime.Now.ToString("yyyyMMdd");
            string date = nowdate.ToString().Substring(0, 4) + "年" +
                    nowdate.ToString().Substring(4, 2) + "月" +
                    nowdate.ToString().Substring(6, 2) + "日";
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 2, 1, date);
            importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 3, 1, bean.Ruku_no);
            //数据集合导出
            int k = 0;
            for (int i = 0; i < this.dataGridView_ruku_chanpin.Rows.Count - 1; i++)
            {
                if (!"".Equals(COMMAND.Command.toString(this.dataGridView_ruku_chanpin.Rows[i].Cells[0].Value).Trim()))
                {
                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 1, this.dataGridView_ruku_chanpin.Rows[i].Cells[0].Value.ToString().Trim());
                    k++;
                    if (this.dataGridView_ruku_chanpin.Rows[i].Cells[1].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, this.dataGridView_ruku_chanpin.Rows[i].Cells[1].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_chanpin.Rows[i].Cells[2].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, this.dataGridView_ruku_chanpin.Rows[i].Cells[2].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_chanpin.Rows[i].Cells[3].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, this.dataGridView_ruku_chanpin.Rows[i].Cells[3].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_chanpin.Rows[i].Cells[4].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, this.dataGridView_ruku_chanpin.Rows[i].Cells[4].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_chanpin.Rows[i].Cells[5].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, this.dataGridView_ruku_chanpin.Rows[i].Cells[5].Value.ToString().Trim());
                    }

                    if (this.dataGridView_ruku_chanpin.Rows[i].Cells[6].Value == null)
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, "");
                    }
                    else
                    {
                        importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, this.dataGridView_ruku_chanpin.Rows[i].Cells[6].Value.ToString().Trim());
                    }
                }
                else
                {
                    continue;
                }

            }
            if (k < 12)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("成品入库1"), 24, 45);
            }
            else if (k > 22 && k < 34)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("成品入库2"), 24, 45);
            }
            else if (k > 44 && k < 56)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("成品入库3"), 24, 45);
            }
            importexcel.SaveAs(path2);
            importexcel.Close();
            MessageBox.Show("导出EXCEL成功，请注意保存当前数据！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //条件查询
        private void tsb_select_Click(object sender, EventArgs e)
        {
            if ("".Equals(this.tst_no.Text.Trim()))
            {
                if (rukustyle == 3)
                {
                    MessageBox.Show("生产日期不能为空！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tst_no.Focus();
                    return;
                }
                else
                {
                    MessageBox.Show("NO不能为空！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tst_no.Focus();
                    return;
                }

            }
            else
            {
                if (rukustyle != 3)
                {
                    if (!COMMAND.Command.IsNum(this.tst_no.Text.Trim()))
                    {
                        MessageBox.Show("NO必须为5位整型数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.tst_no.Focus();
                        return;
                    }
                }
            }
            noselect();
        }
        //no查询
        private void noselect()
        {
            //条件查询SERVICE层
            switch (rukustyle)
            {
                case 0:
                    Bean.Rukuguanli_yuancailiaoBean bean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
                    Service.Rukuguanli_yuancailiaoService rukuguanli_yuancailiaoService = new FWMS.Service.Rukuguanli_yuancailiaoService();
                    bean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    bean = rukuguanli_yuancailiaoService.rukuguanli_yuancailiaoServiceSelectContation(bean);
                    if (bean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无当前NO的入库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.tst_no.Focus();
                        return;
                    }
                    else
                    {
                        datagridviewadddata(bean);
                    }
                    break;
                case 1:
                    Bean.Rukuguanli_tiaoweiliaoBean tiaoweiliaobean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
                    Service.Rukuguanli_tiaoweiliaoService tiaoweiliaoService = new FWMS.Service.Rukuguanli_tiaoweiliaoService();
                    tiaoweiliaobean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    tiaoweiliaobean = tiaoweiliaoService.rukuguanli_tiaoweiliao_ServiceSelectContation(tiaoweiliaobean);
                    if (tiaoweiliaobean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无当前NO的入库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(tiaoweiliaobean);
                    }
                    break;
                case 2:
                    Bean.Rukuguanli_fuliaoBean fuliaobean = new FWMS.Bean.Rukuguanli_fuliaoBean();
                    Service.Rukuguanli_fuliaoService fuliaoService = new FWMS.Service.Rukuguanli_fuliaoService();
                    fuliaobean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    fuliaobean = fuliaoService.rukuguanli_fuliao_ServiceSelectContation(fuliaobean);
                    if (fuliaobean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无当前NO的入库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(fuliaobean);
                    }
                    break;
                case 3:
                    Bean.Rukuguanli_chanpinBean chanpinbean = new FWMS.Bean.Rukuguanli_chanpinBean();
                    Service.Rukuguanli_chanpinService chanpinService = new FWMS.Service.Rukuguanli_chanpinService();
                    chanpinbean.Ruku_yanshou = this.tst_no.Text.Trim();
                    chanpinbean = chanpinService.rukuguanli_chanpin_ServiceSelectContation(chanpinbean);
                    if (chanpinbean.Selectresult == null)
                    {
                        MessageBox.Show("您查询的生产日期没有入库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(chanpinbean);
                    }
                    break;
                default: break;
            }

        }
        //原料入库保存
        private void tb_rukuguanli_ruku_Click(object sender, EventArgs e)
        {
            ruku_yuanliao_data_save();
        }
        //原料保存添加数据
        private void ruku_yuanliao_data_save()
        {
            //原料入库BEAN
            Bean.Rukuguanli_yuancailiaoBean bean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
            //原料入库SERVICE
            Service.Rukuguanli_yuancailiaoService rukuguanli_yuancailiaoService = new FWMS.Service.Rukuguanli_yuancailiaoService();
            //原料入库信息CHECK
            if (!ruku_infocheck(bean, "0"))
            {
                return;
            }
            //入库类型
            bean.Ruku_type = rukustyle.ToString();
            //NO
            bean.Ruku_no = COMMAND.Command.add50(this.tb_no.Text);
            //输入原料入库的条数
            int numcont = this.dataGridView_yuanliaoinfo.Rows.Count;
            //接收输入数据定义集合
            Selectresult = new object[numcont, 7];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if ("".Equals(COMMAND.Command.toString(this.dataGridView_yuanliaoinfo.Rows[j].Cells[0].Value)))
                {
                    continue;
                }
                else
                {
                    if (pinming_same_check(this.dataGridView_yuanliaoinfo.Rows[j].Cells[0].Value.ToString().Trim(), j))
                    {
                        Selectresult[j, 0] = this.dataGridView_yuanliaoinfo.Rows[j].Cells[0].Value.ToString().Trim();
                        i++;
                    }
                    else
                    {
                        MessageBox.Show("重复的品名和规格,无法添加");
                        return;
                    }
                }
                //获取规格
                Selectresult[j, 1] = COMMAND.Command.toString(this.dataGridView_yuanliaoinfo.Rows[j].Cells[1].Value);
                //获取单位
                Selectresult[j, 2] = COMMAND.Command.toString(this.dataGridView_yuanliaoinfo.Rows[j].Cells[2].Value);
                //获取单重
                Selectresult[j, 3] = COMMAND.Command.nulltozero(this.dataGridView_yuanliaoinfo.Rows[j].Cells[3].Value);
                //获取件数
                Selectresult[j, 4] = COMMAND.Command.nulltozero(this.dataGridView_yuanliaoinfo.Rows[j].Cells[4].Value);
                //获取重量
                Selectresult[j, 5] = COMMAND.Command.nulltozero(this.dataGridView_yuanliaoinfo.Rows[j].Cells[5].Value);
                //获取备注
                Selectresult[j, 6] = COMMAND.Command.toString(this.dataGridView_yuanliaoinfo.Rows[j].Cells[6].Value);
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            i = 0;
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            //输入数据条数
            bean.Resultrow = i;
            //向原料入库表中添加数据
            if (!rukuguanli_yuancailiaoService.rukuguanli_yuancailiaoServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //原料入库BEAN
                Bean.Rukuguanli_yuancailiaoBean chanpinkucunbean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
                //原料入库SERVICE
                Service.Rukuguanli_yuancailiaoService service = new FWMS.Service.Rukuguanli_yuancailiaoService();
                //查看库存中是否存在原料入库输入数据 yuanliaoruku_pinming,ruku_guige,ruku_danwei,ruku_danzhong,ruku_jianshu,ruku_zhongliang
                chanpinkucunbean = service.rukuguanli_yuancailiao_kucunguanliServiceSelectContation(chanpinkucunbean);
                rukuguanli_yuancailiaoService.rukuguanli_yuanliaokucundatechuliadd(chanpinkucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //调味料入库保存
        private void bt_ruku_tiaoweiliao_save_Click(object sender, EventArgs e)
        {
            ruku_tiaoweiliao_data_save();
        }
        //调味料保存添加数据
        private void ruku_tiaoweiliao_data_save()
        {
            //调味料BEAN
            Bean.Rukuguanli_tiaoweiliaoBean bean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
            //调味料SERVICE
            Service.Rukuguanli_tiaoweiliaoService rukuguanli_tiaoweiliaoService = new FWMS.Service.Rukuguanli_tiaoweiliaoService();
            if (!ruku_infocheck(bean, "0"))
            {
                return;
            }
            //入库类型
            bean.Ruku_type = rukustyle.ToString();
            //NO
            bean.Ruku_no = COMMAND.Command.add50(this.tb_tiaoweiliao_no.Text);
            //原料基本信息CHECK
            int numcont = this.dataGridView_ruku_tiaoweiliao.Rows.Count;
            Selectresult = new object[numcont, 7];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if ("".Equals(COMMAND.Command.toString(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[0].Value)))
                {
                    continue;
                }
                else
                {
                    if (pinming_same_check(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[0].Value.ToString().Trim(), j))
                    {
                        Selectresult[j, 0] = this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[0].Value.ToString().Trim();
                        i++;
                    }
                    else
                    {
                        MessageBox.Show("品名和规格录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                //获取规格
                Selectresult[j, 1] = COMMAND.Command.toString(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[1].Value);
                //获取单位
                Selectresult[j, 2] = COMMAND.Command.toString(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[2].Value);
                //获取单重
                Selectresult[j, 3] = COMMAND.Command.nulltozero(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[3].Value);
                //获取件数
                Selectresult[j, 4] = COMMAND.Command.nulltozero(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[4].Value);
                //获取重量
                Selectresult[j, 5] = COMMAND.Command.nulltozero(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[5].Value);
                //获取备注
                Selectresult[j, 6] = COMMAND.Command.toString(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[6].Value);
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            i = 0;
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            //输入数据行数
            bean.Resultrow = i;
            if (!rukuguanli_tiaoweiliaoService.rukuguanli_tiaoweiliaoServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Rukuguanli_tiaoweiliaoBean chanpinkucunbean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
                Service.Rukuguanli_tiaoweiliaoService service = new FWMS.Service.Rukuguanli_tiaoweiliaoService();
                chanpinkucunbean = service.rukuguanli_tiaoweiliao_kucunguanliServiceSelectContation(chanpinkucunbean);
                //添加调味料入库数据成功,调整调味料库存
                rukuguanli_tiaoweiliaoService.rukuguanli_tiaoweiliaokucundatechuliadd(chanpinkucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //辅料入库保存
        private void bt_ruku_fuliao_save_Click(object sender, EventArgs e)
        {
            ruku_fuliao_data_save();
        }
        //辅料保存添加数据
        private void ruku_fuliao_data_save()
        {
            //辅料BEAN
            Bean.Rukuguanli_fuliaoBean bean = new FWMS.Bean.Rukuguanli_fuliaoBean();
            //辅料SERVICE
            Service.Rukuguanli_fuliaoService rukuguanli_fuliaoService = new FWMS.Service.Rukuguanli_fuliaoService();
            if (!ruku_infocheck(bean, "0"))
            {
                return;
            }
            //入库类型
            bean.Ruku_type = rukustyle.ToString();
            //NO
            bean.Ruku_no = COMMAND.Command.add50(this.tb_fuliao_no.Text);
            //原料基本信息CHECK
            int numcont = this.dataGridView_ruku_fuliao.Rows.Count;
            Selectresult = new object[numcont, 7];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if ("".Equals(COMMAND.Command.toString(this.dataGridView_ruku_fuliao.Rows[j].Cells[0].Value)))
                {
                    continue;
                }
                else
                {
                    if (pinming_same_check(this.dataGridView_ruku_fuliao.Rows[j].Cells[0].Value.ToString().Trim(), j))
                    {
                        Selectresult[j, 0] = this.dataGridView_ruku_fuliao.Rows[j].Cells[0].Value.ToString().Trim();
                        i++;
                    }
                    else
                    {
                        MessageBox.Show("品名和规格录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                //获取规格
                Selectresult[j, 1] = COMMAND.Command.toString(this.dataGridView_ruku_fuliao.Rows[j].Cells[1].Value);
                //获取单位
                Selectresult[j, 2] = COMMAND.Command.toString(this.dataGridView_ruku_fuliao.Rows[j].Cells[2].Value);
                //获取单重
                Selectresult[j, 3] = COMMAND.Command.nulltozero(this.dataGridView_ruku_fuliao.Rows[j].Cells[3].Value);
                //获取件数
                Selectresult[j, 4] = COMMAND.Command.nulltozero(this.dataGridView_ruku_fuliao.Rows[j].Cells[4].Value);
                //获取重量
                Selectresult[j, 5] = COMMAND.Command.nulltozero(this.dataGridView_ruku_fuliao.Rows[j].Cells[5].Value);
                //获取备注
                Selectresult[j, 6] = COMMAND.Command.toString(this.dataGridView_ruku_fuliao.Rows[j].Cells[6].Value);
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                i = 0;
            }
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            bean.Resultrow = i;

            if (!rukuguanli_fuliaoService.rukuguanli_fuliaoServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Rukuguanli_fuliaoBean chanpinkucunbean = new FWMS.Bean.Rukuguanli_fuliaoBean();
                Service.Rukuguanli_fuliaoService service = new FWMS.Service.Rukuguanli_fuliaoService();
                chanpinkucunbean = service.rukuguanli_fuliao_kucunguanliServiceSelectContation(chanpinkucunbean);
                //调整辅料重量
                rukuguanli_fuliaoService.rukuguanli_fuliaokucundatechuliadd(chanpinkucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //产品入库保存
        private void bt_ruku_chanpin_save_Click(object sender, EventArgs e)
        {
            ruku_chanpin_data_save();
        }
        //产品保存添加数据
        private void ruku_chanpin_data_save()
        {
            Bean.Rukuguanli_chanpinBean bean = new FWMS.Bean.Rukuguanli_chanpinBean();
            Service.Rukuguanli_chanpinService rukuguanli_chanpinService = new FWMS.Service.Rukuguanli_chanpinService();
            if (!ruku_infocheck(bean, "0"))
            {
                return;
            }
            //入库类型
            bean.Ruku_type = rukustyle.ToString();
            //NO
            //原料基本信息CHECK
            int numcont = this.dataGridView_ruku_chanpin.Rows.Count;
            Selectresult = new object[numcont, 7];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value == null)
                {
                    continue;
                }
                else
                {
                    if ("".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value.ToString().Trim()))
                    {
                        continue;
                    }
                    else
                    {
                        Selectresult[j, 0] = this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value.ToString().Trim();
                        i++;
                    }
                }
                //获取规格
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[1].Value == null)
                {
                    Selectresult[j, 1] = "";
                }
                else
                {
                    Selectresult[j, 1] = this.dataGridView_ruku_chanpin.Rows[j].Cells[1].Value.ToString().Trim();
                }
                //获取单位
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[2].Value == null)
                {
                    Selectresult[j, 2] = "";
                }
                else
                {
                    Selectresult[j, 2] = this.dataGridView_ruku_chanpin.Rows[j].Cells[2].Value.ToString().Trim();
                }
                //获取单重
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value == null)
                {
                    Selectresult[j, 3] = 0;
                }
                else
                {
                    if ("".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value))
                    {
                        Selectresult[j, 3] = 0;
                    }
                    else
                    {
                        Selectresult[j, 3] = this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value.ToString().Trim();
                    }
                }
                //获取件数
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value == null)
                {
                    Selectresult[j, 4] = 0;
                }
                else
                {
                    if ("".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value))
                    {
                        Selectresult[j, 4] = 0;
                    }
                    else
                    {
                        Selectresult[j, 4] = this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value.ToString().Trim();
                    }
                }
                //获取重量
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value == null)
                {
                    Selectresult[j, 5] = 0;
                }
                else
                {
                    if ("".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value))
                    {
                        Selectresult[j, 5] = 0;
                    }
                    else
                    {
                        Selectresult[j, 5] = this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value.ToString().Trim();
                    }
                }
                //获取备注
                if (this.dataGridView_ruku_chanpin.Rows[j].Cells[6].Value == null)
                {
                    Selectresult[j, 6] = "";
                }
                else
                {
                    Selectresult[j, 6] = this.dataGridView_ruku_chanpin.Rows[j].Cells[6].Value.ToString().Trim();
                }
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                i = 0;
            }
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            bean.Resultrow = i;
            if (!rukuguanli_chanpinService.rukuguanli_chanpinServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Rukuguanli_chanpinBean chanpinkucunbean = new FWMS.Bean.Rukuguanli_chanpinBean();
                Service.Rukuguanli_chanpinService service = new FWMS.Service.Rukuguanli_chanpinService();
                chanpinkucunbean = service.rukuguanli_chanpin_kucunguanliServiceSelectContation(chanpinkucunbean);
                rukuguanli_chanpinService.rukuguanli_chanpinkucundatechuliadd(chanpinkucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);


            }
        }
        //库存数据处理
        private void kucun_datachuli()
        {
            //条件查询SERVICE层
            switch (rukustyle)
            {
                case 0:
                    Bean.Rukuguanli_yuancailiaoBean bean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
                    Service.Rukuguanli_yuancailiaoService rukuguanli_yuancailiaoService = new FWMS.Service.Rukuguanli_yuancailiaoService();
                    bean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    bean = rukuguanli_yuancailiaoService.rukuguanli_yuancailiaoServiceSelectContation(bean);
                    if (bean.Selectresult == null)
                    {
                        return;
                    }
                    else
                    {
                        datagridviewadddata(bean);
                    }
                    break;
                case 1:
                    Bean.Rukuguanli_tiaoweiliaoBean tiaoweiliaobean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
                    Service.Rukuguanli_tiaoweiliaoService tiaoweiliaoService = new FWMS.Service.Rukuguanli_tiaoweiliaoService();
                    tiaoweiliaobean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    tiaoweiliaobean = tiaoweiliaoService.rukuguanli_tiaoweiliao_ServiceSelectContation(tiaoweiliaobean);
                    if (tiaoweiliaobean.Selectresult == null)
                    {
                        return;
                    }
                    else
                    {
                        datagridviewadddata(tiaoweiliaobean);
                    }
                    break;
                case 2:
                    Bean.Rukuguanli_fuliaoBean fuliaobean = new FWMS.Bean.Rukuguanli_fuliaoBean();
                    Service.Rukuguanli_fuliaoService fuliaoService = new FWMS.Service.Rukuguanli_fuliaoService();
                    fuliaobean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    fuliaobean = fuliaoService.rukuguanli_fuliao_ServiceSelectContation(fuliaobean);
                    if (fuliaobean.Selectresult == null)
                    {
                        return;
                    }
                    else
                    {
                        datagridviewadddata(fuliaobean);
                    }
                    break;
                case 3:
                    Bean.Rukuguanli_chanpinBean chanpinbean = new FWMS.Bean.Rukuguanli_chanpinBean();
                    Service.Rukuguanli_chanpinService chanpinService = new FWMS.Service.Rukuguanli_chanpinService();
                    chanpinbean.Ruku_no = COMMAND.Command.add50(this.tst_no.Text.Trim());
                    chanpinbean = chanpinService.rukuguanli_chanpin_ServiceSelectContation(chanpinbean);
                    if (chanpinbean.Selectresult == null)
                    {
                        return;
                    }
                    else
                    {
                        datagridviewadddata(chanpinbean);
                    }
                    break;
                default: break;
            }
        }
        //接收数据并显示
        private void datagridviewadddata(object bean)
        {
            switch (rukustyle)
            {
                case 0:

                    Bean.Rukuguanli_yuancailiaoBean yuancailiaobean = (Bean.Rukuguanli_yuancailiaoBean)bean;
                    string data = yuancailiaobean.Selectresult[0, 2].ToString().Substring(0, 4) + "年" +
                    yuancailiaobean.Selectresult[0, 2].ToString().Substring(4, 2) + "月" +
                    yuancailiaobean.Selectresult[0, 2].ToString().Substring(6, 2) + "日";
                    //到货日期
                    this.dateTimePicker_daohuo.Text = data.Trim();
                    //NO
                    this.tb_no.Text = yuancailiaobean.Selectresult[0, 3].ToString().Trim();
                    data = yuancailiaobean.Selectresult[0, 4].ToString().Substring(0, 4) + "年" +
                           yuancailiaobean.Selectresult[0, 4].ToString().Substring(4, 2) + "月" +
                           yuancailiaobean.Selectresult[0, 4].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.dateTimePicker_yanshou.Text = data;
                    //发货单位
                    this.tb_fahuodanwei.Text = yuancailiaobean.Selectresult[0, 5].ToString().Trim();
                    //清除数据集
                    this.dataGridView_yuanliaoinfo.Rows.Clear();
                    for (int j = 0; j < yuancailiaobean.Resultrow; j++)
                    {
                        if ("0".Equals(yuancailiaobean.Selectresult[j, 9].ToString().Trim()))
                        {
                            yuancailiaobean.Selectresult[j, 9] = "";
                        }
                        if ("0".Equals(yuancailiaobean.Selectresult[j, 10].ToString().Trim()))
                        {
                            yuancailiaobean.Selectresult[j, 10] = "";
                        }
                        this.dataGridView_yuanliaoinfo.Rows.Add();
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[0].Value = yuancailiaobean.Selectresult[j, 6];
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[1].Value = yuancailiaobean.Selectresult[j, 7];
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[2].Value = yuancailiaobean.Selectresult[j, 8];
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[3].Value = yuancailiaobean.Selectresult[j, 9];
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[4].Value = Convert.ToString(yuancailiaobean.Selectresult[j, 10]);
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[5].Value = Convert.ToString(yuancailiaobean.Selectresult[j, 11]);
                        this.dataGridView_yuanliaoinfo.Rows[j].Cells[6].Value = Convert.ToString(yuancailiaobean.Selectresult[j, 12]);
                    }
                    break;
                case 1:
                    Bean.Rukuguanli_tiaoweiliaoBean tiaoweiliaobean = (Bean.Rukuguanli_tiaoweiliaoBean)bean;
                    string tiaoweiliaodata = tiaoweiliaobean.Selectresult[0, 2].ToString().Substring(0, 4) + "年" +
                    tiaoweiliaobean.Selectresult[0, 2].ToString().Substring(4, 2) + "月" +
                    tiaoweiliaobean.Selectresult[0, 2].ToString().Substring(6, 2) + "日";
                    //到货日期
                    this.dateTimePicker_tiaoweiliao_daohuo.Text = tiaoweiliaodata.Trim();
                    //NO
                    this.tb_tiaoweiliao_no.Text = tiaoweiliaobean.Selectresult[0, 3].ToString().Trim();
                    tiaoweiliaodata = tiaoweiliaobean.Selectresult[0, 4].ToString().Substring(0, 4) + "年" +
                           tiaoweiliaobean.Selectresult[0, 4].ToString().Substring(4, 2) + "月" +
                           tiaoweiliaobean.Selectresult[0, 4].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.dateTimePicker_tiaoweiliao_yanshou.Text = tiaoweiliaodata;
                    //发货单位
                    this.tb_tiaoweiliao_fahuodanwei.Text = tiaoweiliaobean.Selectresult[0, 5].ToString().Trim();
                    //清除数据集
                    this.dataGridView_ruku_tiaoweiliao.Rows.Clear();
                    for (int j = 0; j < tiaoweiliaobean.Resultrow; j++)
                    {
                        if ("0".Equals(tiaoweiliaobean.Selectresult[j, 9].ToString().Trim()))
                        {
                            tiaoweiliaobean.Selectresult[j, 9] = "";
                        }
                        if ("0".Equals(tiaoweiliaobean.Selectresult[j, 10].ToString().Trim()))
                        {
                            tiaoweiliaobean.Selectresult[j, 10] = "";
                        }
                        this.dataGridView_ruku_tiaoweiliao.Rows.Add();
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[0].Value = tiaoweiliaobean.Selectresult[j, 6];
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[1].Value = tiaoweiliaobean.Selectresult[j, 7];
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[2].Value = tiaoweiliaobean.Selectresult[j, 8];
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[3].Value = tiaoweiliaobean.Selectresult[j, 9];
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[4].Value = Convert.ToString(tiaoweiliaobean.Selectresult[j, 10]);
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[5].Value = Convert.ToString(tiaoweiliaobean.Selectresult[j, 11]);
                        this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[6].Value = Convert.ToString(tiaoweiliaobean.Selectresult[j, 12]);
                    }
                    break;
                case 2:
                    Bean.Rukuguanli_fuliaoBean fuliaobean = (Bean.Rukuguanli_fuliaoBean)bean;
                    string fuliaodata = fuliaobean.Selectresult[0, 2].ToString().Substring(0, 4) + "年" +
                    fuliaobean.Selectresult[0, 2].ToString().Substring(4, 2) + "月" +
                    fuliaobean.Selectresult[0, 2].ToString().Substring(6, 2) + "日";
                    //到货日期
                    this.dateTimePicker_fuliao_daohuo.Text = fuliaodata.Trim();
                    //NO
                    this.tb_fuliao_no.Text = fuliaobean.Selectresult[0, 3].ToString().Trim();
                    fuliaodata = fuliaobean.Selectresult[0, 4].ToString().Substring(0, 4) + "年" +
                           fuliaobean.Selectresult[0, 4].ToString().Substring(4, 2) + "月" +
                           fuliaobean.Selectresult[0, 4].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.dateTimePicker_fuliao_yanshou.Text = fuliaodata;
                    //发货单位
                    this.tb_fuliao_fahuodanwei.Text = fuliaobean.Selectresult[0, 5].ToString().Trim();
                    //清除数据集
                    this.dataGridView_ruku_fuliao.Rows.Clear();
                    for (int j = 0; j < fuliaobean.Resultrow; j++)
                    {
                        if ("0".Equals(fuliaobean.Selectresult[j, 9].ToString().Trim()))
                        {
                            fuliaobean.Selectresult[j, 9] = "";
                        }
                        if ("0".Equals(fuliaobean.Selectresult[j, 10].ToString().Trim()))
                        {
                            fuliaobean.Selectresult[j, 10] = "";
                        }
                        if ("0".Equals(fuliaobean.Selectresult[j, 11].ToString().Trim()))
                        {
                            fuliaobean.Selectresult[j, 11] = "";
                        }
                        this.dataGridView_ruku_fuliao.Rows.Add();
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[0].Value = fuliaobean.Selectresult[j, 6];
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[1].Value = fuliaobean.Selectresult[j, 7].ToString().Trim();
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[2].Value = fuliaobean.Selectresult[j, 8].ToString().Trim();
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[3].Value = fuliaobean.Selectresult[j, 9].ToString().Trim();
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[4].Value = fuliaobean.Selectresult[j, 10].ToString().Trim();
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[5].Value = fuliaobean.Selectresult[j, 11].ToString().Trim();
                        this.dataGridView_ruku_fuliao.Rows[j].Cells[6].Value = fuliaobean.Selectresult[j, 12].ToString().Trim();
                    }
                    break;
                case 3:
                    //清除数据集
                    this.dataGridView_ruku_chanpin.Rows.Clear();
                    Bean.Rukuguanli_chanpinBean chanpinbean = (Bean.Rukuguanli_chanpinBean)bean;
                    if (COMMAND.CommandBean.rukuyuancailiaoresult == null)
                    {
                        if ("".Equals(COMMAND.Command.toString(chanpinbean.Selectresult[0, 1])))
                        {
                            chanpinbean.Selectresult[0, 1] = System.DateTime.Now.ToString("yyyyMMdd"); 
                        }
                         string chanpindata = chanpinbean.Selectresult[0, 0].ToString().Substring(0, 4) + "年" +
                        chanpinbean.Selectresult[0, 0].ToString().Substring(4, 2) + "月" +
                        chanpinbean.Selectresult[0, 0].ToString().Substring(6, 2) + "日";
                        //到货日期
                        this.dateTimePicker_chanpin_yanshoudate.Text = chanpindata.Trim();
                        chanpindata = chanpinbean.Selectresult[0, 1].ToString().Substring(0, 4) + "年" +
                               chanpinbean.Selectresult[0, 1].ToString().Substring(4, 2) + "月" +
                               chanpinbean.Selectresult[0, 1].ToString().Substring(6, 2) + "日";
                        //验收日期
                        this.TimePicker_chanpin_daohuo.Text = chanpindata;
                        //清除数据集
                        this.dataGridView_ruku_chanpin.Rows.Clear();
                        for (int j = 0; j < chanpinbean.Resultrow; j++)
                        {
                            this.dataGridView_ruku_chanpin.Rows.Add();
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 2]);
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[1].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 3]);
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[2].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 4]);
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value = COMMAND.Command.nulltozero(chanpinbean.Selectresult[j, 5]);
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value = COMMAND.Command.nulltozero(chanpinbean.Selectresult[j, 6]);
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value = COMMAND.Command.nulltozero(chanpinbean.Selectresult[j, 7]);
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[6].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 8]);
                        }
                    }
                    else
                    {
                        for (int j = 0; j < chanpinbean.Selectresult.Length / 6; j++)
                        {
                            if ("0".Equals(chanpinbean.Selectresult[j, 2].ToString().Trim()))
                            {
                                chanpinbean.Selectresult[j, 2] = "";
                            }
                            if ("0".Equals(chanpinbean.Selectresult[j, 3].ToString().Trim()))
                            {
                                chanpinbean.Selectresult[j, 3] = "";
                            }
                            if ("0".Equals(chanpinbean.Selectresult[j, 4].ToString().Trim()))
                            {
                                chanpinbean.Selectresult[j, 4] = "";
                            }
                            this.dataGridView_ruku_chanpin.Rows.Add();
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value = chanpinbean.Selectresult[j, 0];
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[1].Value = chanpinbean.Selectresult[j, 1].ToString().Trim();
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[2].Value = chanpinbean.Selectresult[j, 2].ToString().Trim();
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value = chanpinbean.Selectresult[j, 4].ToString().Trim();
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value = chanpinbean.Selectresult[j, 5].ToString().Trim();
                            this.dataGridView_ruku_chanpin.Rows[j].Cells[6].Value = chanpinbean.Selectresult[j, 3].ToString().Trim();
                        }
                    }
                    break;
                default: break;
            }
        }
        //原材料当前编辑状态停止时
        private void dataGridView_yuanliaoinfo_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView_yuanliaoinfo.CurrentCell.ColumnIndex == 3 || this.dataGridView_yuanliaoinfo.CurrentCell.ColumnIndex == 4)
            {
                if (this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[3].Value != null
                && this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[4].Value != null
                && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[3].Value)
                && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[4].Value))
                {
                    //this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[5].Value =
                    if (COMMAND.Command.IsFloat(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[3].Value.ToString().Trim())
                        && COMMAND.Command.IsNum(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[4].Value.ToString().Trim())
                        )
                    {
                        float cell3 = float.Parse(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[3].Value.ToString().Trim());
                        int cell4 = int.Parse(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[4].Value.ToString().Trim());
                        float ji = cell3 * cell4;
                        this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[5].Value = ji.ToString();
                    }
                }
                else
                {
                    this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[5].Value = null;
                }
            }
        }
        //调味料当前编辑状态停止时
        private void dataGridView_ruku_tiaoweiliao_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView_ruku_tiaoweiliao.CurrentCell.ColumnIndex == 3 || this.dataGridView_ruku_tiaoweiliao.CurrentCell.ColumnIndex == 4)
            {
                if (this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[3].Value != null
                && this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[4].Value != null
                && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[3].Value)
                && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[4].Value))
                {
                    //this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[5].Value =
                    if (COMMAND.Command.IsFloat(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[3].Value.ToString().Trim())
                        && COMMAND.Command.IsNum(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[4].Value.ToString().Trim())
                        )
                    {
                        float cell3 = float.Parse(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[3].Value.ToString().Trim());
                        int cell4 = int.Parse(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[4].Value.ToString().Trim());
                        float ji = cell3 * cell4;
                        this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[5].Value = ji.ToString();
                    }
                }
                else
                {
                    this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[5].Value = null;
                }
            }
        }
        //辅料当前编辑状态停止时
        private void dataGridView_ruku_fuliao_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView_ruku_fuliao.CurrentCell.ColumnIndex == 3 || this.dataGridView_ruku_fuliao.CurrentCell.ColumnIndex == 4)
            {
                if (this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[3].Value != null
                && this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[4].Value != null
                && !"".Equals(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[3].Value)
                && !"".Equals(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[4].Value))
                {
                    //this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[5].Value =
                    if (COMMAND.Command.IsFloat(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[3].Value.ToString().Trim())
                        && COMMAND.Command.IsNum(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[4].Value.ToString().Trim())
                        )
                    {
                        float cell3 = float.Parse(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[3].Value.ToString().Trim());
                        int cell4 = int.Parse(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[4].Value.ToString().Trim());
                        float ji = cell3 * cell4;
                        this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[5].Value = ji.ToString();
                    }
                }
                else
                {
                    this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[5].Value = null;
                }
            }
        }
        //产品当前编辑状态停止时
        private void dataGridView_ruku_chanpin_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {

        }
        //原材料单元格编辑CHECK
        private void dataGridView_yuanliaoinfo_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dataGridView_yuanliaoinfo.CurrentCell.ColumnIndex == 3 || this.dataGridView_yuanliaoinfo.CurrentCell.ColumnIndex == 4)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(dataGridView_yuanliaoinfo_KeyPress);
            }
        }
        //调味料单元格编辑CHECK
        private void dataGridView_ruku_tiaoweiliao_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dataGridView_ruku_tiaoweiliao.CurrentCell.ColumnIndex == 3 || this.dataGridView_ruku_tiaoweiliao.CurrentCell.ColumnIndex == 4)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(dataGridView_ruku_tiaoweiliao_KeyPress);
            }
        }
        //辅料单元格编辑CHECK
        private void dataGridView_ruku_fuliao_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dataGridView_ruku_fuliao.CurrentCell.ColumnIndex == 3 || this.dataGridView_ruku_fuliao.CurrentCell.ColumnIndex == 4)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(dataGridView_ruku_fuliao_KeyPress);
            }
        }
        //产品单元格编辑CHECK
        private void dataGridView_ruku_chanpin_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dataGridView_ruku_chanpin.CurrentCell.ColumnIndex == 3 || this.dataGridView_ruku_chanpin.CurrentCell.ColumnIndex == 4)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(dataGridView_ruku_chanpin_KeyPress);
            }
        }
        //原材料按键CHECK
        private void dataGridView_yuanliaoinfo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.dataGridView_yuanliaoinfo.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.dataGridView_yuanliaoinfo.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }
        //调味料按键CHECK
        private void dataGridView_ruku_tiaoweiliao_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.dataGridView_ruku_tiaoweiliao.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.dataGridView_ruku_tiaoweiliao.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }
        //辅料按键CHECK
        private void dataGridView_ruku_fuliao_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.dataGridView_ruku_fuliao.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.dataGridView_ruku_fuliao.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }
        //产品按键CHECK
        private void dataGridView_ruku_chanpin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.dataGridView_ruku_chanpin.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.dataGridView_ruku_chanpin.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }

        //原材料NO控制
        private void tb_no_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13))
                e.Handled = true;
            else
                e.Handled = false;
        }
        //调味料NO控制
        private void tb_tiaoweiliao_no_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13))
                e.Handled = true;
            else
                e.Handled = false;
        }
        //辅料NO控制
        private void tb_fuliao_no_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13))
                e.Handled = true;
            else
                e.Handled = false;
        }
        //产品NO控制
        private void tb_chanpin_no_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13))
                e.Handled = true;
            else
                e.Handled = false;
        }
        //入库基本信息CHEDK
        private bool ruku_infocheck(object bean, string export)
        {
            switch (rukustyle)
            {
                case 0:
                    //原料入库BEAN
                    Bean.Rukuguanli_yuancailiaoBean yuancailiaobean = (Bean.Rukuguanli_yuancailiaoBean)bean;
                    //到货日期
                    yuancailiaobean.Ruku_daohuo = this.dateTimePicker_daohuo.Value.ToString("yyyyMMdd");
                    //验收日期
                    yuancailiaobean.Ruku_yanshou = this.dateTimePicker_yanshou.Value.ToString("yyyyMMdd");
                    //NO
                    yuancailiaobean.Ruku_no = this.tb_no.Text.Trim();
                    //发货单位
                    yuancailiaobean.Ruku_fahuodanwei = this.tb_fahuodanwei.Text.Trim();
                    //入库基本信息必须全部添写
                    if ("".Equals(yuancailiaobean.Ruku_daohuo) || "".Equals(yuancailiaobean.Ruku_yanshou) || "".Equals(yuancailiaobean.Ruku_no) || "".Equals(yuancailiaobean.Ruku_fahuodanwei))
                    {
                        MessageBox.Show("入库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.dataGridView_yuanliaoinfo.Rows.Count; j++)
                    {
                        if (this.dataGridView_yuanliaoinfo.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }
                        //单重输入格式验证
                        if (this.dataGridView_yuanliaoinfo.Rows[j].Cells[3].Value != null && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.dataGridView_yuanliaoinfo.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.dataGridView_yuanliaoinfo.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单重只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //重量输入格式验证
                        if (this.dataGridView_yuanliaoinfo.Rows[j].Cells[5].Value != null && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.dataGridView_yuanliaoinfo.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.dataGridView_yuanliaoinfo.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.dataGridView_yuanliaoinfo.Rows[j].Cells[4].Value != null && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.dataGridView_yuanliaoinfo.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.dataGridView_yuanliaoinfo.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        if (!pinming_same_check(this.dataGridView_yuanliaoinfo.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名和规格录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    if (!"1".Equals(export))
                    {
                        //原料入库BEAN
                        Bean.Rukuguanli_yuancailiaoBean kucunbean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
                        //原料入库SERVICE
                        Service.Rukuguanli_yuancailiaoService rukuguanli_yuancailiaoService = new FWMS.Service.Rukuguanli_yuancailiaoService();
                        //NOKGN号不足补足五位
                        kucunbean.Ruku_no = COMMAND.Command.add50(this.tb_no.Text.Trim());
                        //按输入数据进行查询是添加还是覆盖查询目标 yuanliaoruku_pinming,ruku_guige,ruku_danwei,ruku_danzhong,ruku_jianshu,ruku_zhongliang
                        kucunbean = rukuguanli_yuancailiaoService.rukuguanli_yuancailiao_kucunguanliServiceSelectContation(kucunbean);
                        if (kucunbean.Selectresult != null)
                        {
                            if (MessageBox.Show("输入NO号己存在是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                //如果是覆盖原料入库数据向库存中添加数据
                                rukuguanli_yuancailiaoService.rukuguanli_yuanliaokucundatechulijian(kucunbean);
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                    return true;
                case 1:
                    Bean.Rukuguanli_tiaoweiliaoBean tiaoweiliaobean = (Bean.Rukuguanli_tiaoweiliaoBean)bean;
                    //到货日期
                    tiaoweiliaobean.Ruku_daohuo = this.dateTimePicker_tiaoweiliao_daohuo.Value.ToString("yyyyMMdd");
                    //验收日期
                    tiaoweiliaobean.Ruku_yanshou = this.dateTimePicker_tiaoweiliao_yanshou.Value.ToString("yyyyMMdd");
                    //NO
                    tiaoweiliaobean.Ruku_no = this.tb_tiaoweiliao_no.Text.Trim();
                    //发货单位
                    tiaoweiliaobean.Ruku_fahuodanwei = this.tb_tiaoweiliao_fahuodanwei.Text.Trim();
                    //入库基本信息必须全部添写
                    if ("".Equals(tiaoweiliaobean.Ruku_daohuo) || "".Equals(tiaoweiliaobean.Ruku_yanshou) || "".Equals(tiaoweiliaobean.Ruku_no) || "".Equals(tiaoweiliaobean.Ruku_fahuodanwei))
                    {
                        MessageBox.Show("入库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.dataGridView_ruku_tiaoweiliao.Rows.Count; j++)
                    {
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }
                        //单重输入格式验证
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[3].Value != null && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_tiaoweiliao.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单重只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //重量输入格式验证
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[5].Value != null && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_tiaoweiliao.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[4].Value != null && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_tiaoweiliao.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        if (!pinming_same_check(this.dataGridView_ruku_tiaoweiliao.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名和规格录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    if (!"1".Equals(export))
                    {
                        //调味料入库BEAN
                        Bean.Rukuguanli_tiaoweiliaoBean tiaoweiliaokucunbean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
                        //调味料入库SERVICE
                        Service.Rukuguanli_tiaoweiliaoService rukuguanli_tiaoweiliaoService = new FWMS.Service.Rukuguanli_tiaoweiliaoService();
                        //获取调味料入库NO号
                        tiaoweiliaokucunbean.Ruku_no = COMMAND.Command.add50(this.tb_tiaoweiliao_no.Text.Trim());
                        //查询是否存在输入的NO号的数据
                        tiaoweiliaokucunbean = rukuguanli_tiaoweiliaoService.rukuguanli_tiaoweiliao_kucunguanliServiceSelectContation(tiaoweiliaokucunbean);
                        //如果输入的数据,数据库中己存在则为修改
                        if (tiaoweiliaokucunbean.Selectresult != null)
                        {
                            if (MessageBox.Show("输入NO号己存在是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                //修改数据前调整库存 yuanliaoruku_pinming,ruku_guige,ruku_danwei,ruku_danzhong,ruku_jianshu,ruku_zhongliang
                                rukuguanli_tiaoweiliaoService.rukuguanli_tiaoweiliaokucundatechulijian(tiaoweiliaokucunbean);
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                    return true;
                case 2:
                    Bean.Rukuguanli_fuliaoBean fuliaobean = (Bean.Rukuguanli_fuliaoBean)bean;
                    //到货日期
                    fuliaobean.Ruku_daohuo = this.dateTimePicker_fuliao_daohuo.Value.ToString("yyyyMMdd");
                    //验收日期
                    fuliaobean.Ruku_yanshou = this.dateTimePicker_fuliao_yanshou.Value.ToString("yyyyMMdd");
                    //NO
                    fuliaobean.Ruku_no = this.tb_fuliao_no.Text.Trim();
                    //发货单位
                    fuliaobean.Ruku_fahuodanwei = this.tb_fuliao_fahuodanwei.Text.Trim();
                    //入库基本信息必须全部添写
                    if ("".Equals(fuliaobean.Ruku_daohuo) || "".Equals(fuliaobean.Ruku_yanshou) || "".Equals(fuliaobean.Ruku_no) || "".Equals(fuliaobean.Ruku_fahuodanwei))
                    {
                        MessageBox.Show("入库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.dataGridView_ruku_fuliao.Rows.Count; j++)
                    {
                        if (this.dataGridView_ruku_fuliao.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }

                        //单重输入格式验证
                        if (this.dataGridView_ruku_fuliao.Rows[j].Cells[3].Value != null && !"".Equals(this.dataGridView_ruku_fuliao.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.dataGridView_ruku_fuliao.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_fuliao.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单重只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //重量输入格式验证
                        if (this.dataGridView_ruku_fuliao.Rows[j].Cells[5].Value != null && !"".Equals(this.dataGridView_ruku_fuliao.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.dataGridView_ruku_fuliao.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_fuliao.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //件数输入格式验证
                        if (this.dataGridView_ruku_fuliao.Rows[j].Cells[4].Value != null && !"".Equals(this.dataGridView_ruku_fuliao.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.dataGridView_ruku_fuliao.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_fuliao.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        if (!pinming_same_check(this.dataGridView_ruku_fuliao.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名和规格录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    if (!"1".Equals(export))
                    {
                        //辅料BEAN
                        Bean.Rukuguanli_fuliaoBean fuliaokucunbean = new FWMS.Bean.Rukuguanli_fuliaoBean();
                        //辅料SERVICE
                        Service.Rukuguanli_fuliaoService rukuguanli_fuliaoService = new FWMS.Service.Rukuguanli_fuliaoService();
                        fuliaokucunbean.Ruku_no = COMMAND.Command.add50(this.tb_fuliao_no.Text.Trim());
                        //根据辅料入库输入数据进行条件查询
                        fuliaokucunbean = rukuguanli_fuliaoService.rukuguanli_fuliao_kucunguanliServiceSelectContation(fuliaokucunbean);
                        //如果输入数据数据库中存在
                        if (fuliaokucunbean.Selectresult != null)
                        {
                            if (MessageBox.Show("输入NO号己存在是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                //调整辅料库存
                                rukuguanli_fuliaoService.rukuguanli_fuliaokucundatechulijian(fuliaokucunbean);
                                return true;
                            }
                            else
                            {
                                return false;
                            }

                        }
                    }
                    return true;
                case 3:
                    Bean.Rukuguanli_chanpinBean chanpinbean = (Bean.Rukuguanli_chanpinBean)bean;
                    //到货日期
                    chanpinbean.Ruku_yanshou = this.dateTimePicker_chanpin_yanshoudate.Value.ToString("yyyyMMdd");
                    //验收日期
                    chanpinbean.Ruku_daohuo = this.TimePicker_chanpin_daohuo.Value.ToString("yyyyMMdd");
                    //入库基本信息必须全部添写
                    if ("".Equals(chanpinbean.Ruku_daohuo) || "".Equals(chanpinbean.Ruku_yanshou) || "".Equals(chanpinbean.Ruku_fahuodanwei))
                    {
                        MessageBox.Show("入库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.dataGridView_ruku_chanpin.Rows.Count; j++)
                    {
                        if (this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }

                        //单重输入格式验证
                        if (this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value != null && !"".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.dataGridView_ruku_chanpin.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_chanpin.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单重只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //重量输入格式验证
                        if (this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value != null && !"".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.dataGridView_ruku_chanpin.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_chanpin.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value != null && !"".Equals(this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.dataGridView_ruku_chanpin.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.dataGridView_ruku_chanpin.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        if (!pinming_same_check(this.dataGridView_ruku_chanpin.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名和规格录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    if (!"1".Equals(export))
                    {
                        Bean.Rukuguanli_chanpinBean chanpinkucunbean = new FWMS.Bean.Rukuguanli_chanpinBean();
                        Service.Rukuguanli_chanpinService rukuguanli_chanpinService = new FWMS.Service.Rukuguanli_chanpinService();
                        chanpinkucunbean = rukuguanli_chanpinService.rukuguanli_chanpin_kucunguanliServiceSelectContation(chanpinkucunbean);
                        if (chanpinkucunbean.Selectresult != null)
                        {
                            if (MessageBox.Show("输入日期数据己存在是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                rukuguanli_chanpinService.rukuguanli_chanpinkucundatechulijian(chanpinkucunbean);
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                    return true;
                default: return true;
            }
        }
        /**
        * DataGridView 单击右键删除选择行处理
        * 可以一次删除选中多行，单行，禁止删除最后一行
        * 
        * */
        private void ToolStripMenuItem_deleteLine_Click(object sender, EventArgs e)
        {
            //当前选中单元格
            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_yuanliaoinfo.SelectedCells;
            //当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_yuanliaoinfo.SelectedRows;

            if (selectedRows.Count == 0)
            {
                foreach (DataGridViewCell cell in selectedCells)
                {
                    if (cell.RowIndex != -1 && !this.dataGridView_yuanliaoinfo.Rows[cell.RowIndex].IsNewRow)
                    {
                        this.dataGridView_yuanliaoinfo.Rows.RemoveAt(cell.RowIndex);
                    }
                }

            }
            else
            {
                foreach (DataGridViewRow row in selectedRows)
                {
                    // MessageBox.Show(row.Index.ToString());
                    if (!row.IsNewRow)
                    {
                        this.dataGridView_yuanliaoinfo.Rows.Remove(row);
                    }
                }
            }
        }
        /**
        * DataGridView 单击右键添加行
        * 在当前选中行上面添加新行
        * 
        * */
        private void ToolStripMenuItem_addrowUp_Click(object sender, EventArgs e)
        {
            //当前选中单元格
            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_yuanliaoinfo.SelectedCells;
            //当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_yuanliaoinfo.SelectedRows;
            List<int> ss = new List<int>();
            DataGridViewRow[] rows;
            //判定当前选择行的最小行数

            for (int i = 0; i < selectedCells.Count; i++)
            {
                ss.Add(selectedCells[i].RowIndex);
            }

            ss.Sort();

            if (selectedRows.Count != 0)
            {
                rows = new DataGridViewRow[selectedRows.Count];
            }
            else
            {
                rows = new DataGridViewRow[selectedCells.Count];
            }

            for (int i = 0; i < rows.Length; i++)
            {
                rows[i] = new DataGridViewRow();
            }
            if (selectedRows.Count != 0)
            {

                this.dataGridView_yuanliaoinfo.Rows.InsertRange(ss[0], rows);
            }
            else
            {
                this.dataGridView_yuanliaoinfo.Rows.InsertRange(ss[0], rows);
            }

        }
        /**
        * DataGridView 单击右键添加行
        * 在当前选中行下面添加新行
        * 
        * */
        private void ToolStripMenuItem_addRowDown_Click(object sender, EventArgs e)
        {
            try
            {
                //当前选中单元格
                DataGridViewSelectedCellCollection selectedCells = this.dataGridView_yuanliaoinfo.SelectedCells;
                //当前选中行
                DataGridViewSelectedRowCollection selectedRows = this.dataGridView_yuanliaoinfo.SelectedRows;

                DataGridViewRow[] rows;
                int maxIndex = 0;
                if (selectedRows.Count != 0)
                {
                    //判定当前选择行的最大行数
                    foreach (DataGridViewRow row in selectedRows)
                    {
                        if (row.Index > maxIndex)
                        {
                            maxIndex = row.Index;
                        }
                    }
                    rows = new DataGridViewRow[selectedRows.Count];
                }
                else
                {
                    //判定当前选择单元格所在行的最大行数
                    foreach (DataGridViewCell cell in selectedCells)
                    {
                        if (cell.RowIndex > maxIndex)
                        {
                            maxIndex = cell.RowIndex;
                        }
                    }
                    rows = new DataGridViewRow[selectedCells.Count];
                }
                for (int i = 0; i < rows.Length; i++)
                {
                    rows[i] = new DataGridViewRow();
                }
                if (selectedRows.Count != 0)
                {

                    this.dataGridView_yuanliaoinfo.Rows.InsertRange(maxIndex + 1, rows);
                }
                else
                {
                    this.dataGridView_yuanliaoinfo.Rows.InsertRange(maxIndex + 1, rows);
                }
            }
            catch (Exception)
            {
                //异常状态
                MessageBox.Show("不能在最后一行后面添加行！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /**
         * 
         * 如果没有选中行或者选中的单元位于多行
         * 则屏蔽添加和删除按钮
         * 
         * 
         * */
        private void dataGridView_yuanliaoinfo_MouseDown(object sender, MouseEventArgs e)
        {
            // 当前选中单元格
            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_yuanliaoinfo.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_yuanliaoinfo.SelectedRows;
            Boolean isEditable = true;

            //没有选中行或者选中的单元位于多行
            if (selectedRows.Count == 0 && selectedCells.Count > 1)
            {

                int firstSelectedRow = selectedCells[0].RowIndex;
                int rowIndex = 0;
                foreach (DataGridViewCell cell in selectedCells)
                {
                    //判断是否选中多行的单元格
                    rowIndex = cell.RowIndex;
                    if (firstSelectedRow != rowIndex)
                    {
                        isEditable = false;
                    }
                }
            }
            //鼠标右键单击事件并且单元格不可添加删除状态
            if (e.Button == MouseButtons.Right && isEditable == false)
            {
                this.ToolStripMenuItem_addrowUp.Enabled = false;
                this.ToolStripMenuItem_addRowDown.Enabled = false;
            }
            else
            {
                this.ToolStripMenuItem_addrowUp.Enabled = true;
                this.ToolStripMenuItem_addRowDown.Enabled = true;
            }

            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
            {
                this.toolStripMenuItem1.Enabled = false;
            }
            else
            {
                this.toolStripMenuItem1.Enabled = true;
            }

        }
        /**
         * 
         * 剪贴板粘贴
         * 
         * 
         * */
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.dataGridView_yuanliaoinfo.CurrentCell == null)
                return;
            int insertRowIndex = this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_yuanliaoinfo.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_yuanliaoinfo.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_yuanliaoinfo.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.dataGridView_yuanliaoinfo.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单重只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }
                    //重新计算重量（实收数）
                    if (this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[3].Value != null
                        && this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[4].Value != null
                        && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[3].Value)
                        && !"".Equals(this.dataGridView_yuanliaoinfo.Rows[this.dataGridView_yuanliaoinfo.CurrentCell.RowIndex].Cells[4].Value))
                    {

                        this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[5].Value = Convert.ToString(float.Parse(this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[3].Value.ToString()) * Convert.ToInt32(this.dataGridView_yuanliaoinfo.Rows[insertRowIndex].Cells[4].Value));
                    }



                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


        }
        /**
         * 
         * 剪贴板复制
         * 
         * 
         * */
        private void ToolStripMenuItem_copy_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.dataGridView_yuanliaoinfo.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }
        /**
         * 
         * 选中单元格数据清空
         * 
         * 
         * */
        private void ToolStripMenuItem_clear_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.dataGridView_yuanliaoinfo.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                if (cell.ColumnIndex == 3 || cell.ColumnIndex == 4)
                {
                    this.dataGridView_yuanliaoinfo.Rows[cell.RowIndex].Cells[5].Value = null;
                }
                cell.Value = null;
            }
        }
        //选项卡切换
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            rukustyle = this.tabControl1.SelectedIndex;
            switch (rukustyle)
            {
                case 0: lbl_sum.Text = "0"; lbl_sum.Visible = false; this.tst_no.MaxLength = 5; toolStripLabel3.Text = "NO"; ruku_yuancailiao_init(); break;
                case 1: lbl_sum.Text = "0"; lbl_sum.Visible = false; this.tst_no.MaxLength = 5; toolStripLabel3.Text = "NO"; ruku_tiaoweiliao_init(); break;
                case 2: lbl_sum.Text = "0"; lbl_sum.Visible = false; this.tst_no.MaxLength = 5; toolStripLabel3.Text = "NO"; ruku_fuliao_init(); break;
                case 3: lbl_sum.Text = "0"; lbl_sum.Visible = false; this.toolStrip2.Width = 500; this.tst_no.MaxLength = 8; toolStripLabel3.Text = "生产日期(YYYYMMDD)"; this.tst_no.Text = ""; ruku_chanpin_init(); break;
                default: break;
            }
        }
        //原材料初始化
        private void ruku_yuancailiao_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            rukustyle = 0;//原材料
            Bean.Rukuguanli_yuancailiaoBean bean = new FWMS.Bean.Rukuguanli_yuancailiaoBean();
            Service.Rukuguanli_yuancailiaoService service = new FWMS.Service.Rukuguanli_yuancailiaoService();
            bean = service.rukuguanli_ServiceSelect();
            //初始化原材料品名
            this.dataGridView_yuanliaoinfo.Rows.Clear();
            if (this.dataGridView_yuanliaoinfo.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.dataGridView_yuanliaoinfo.Rows.Add();
                }
                this.dateTimePicker_daohuo.Value = DateTime.Now;
                this.dateTimePicker_yanshou.Value = DateTime.Now;
                this.tb_no.Text = "";
                this.tb_fahuodanwei.Text = "";
            }
        }
        //调味料初始化
        private void ruku_tiaoweiliao_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            rukustyle = 1;//调味料
            Bean.Rukuguanli_tiaoweiliaoBean bean = new FWMS.Bean.Rukuguanli_tiaoweiliaoBean();
            Service.Rukuguanli_tiaoweiliaoService service = new FWMS.Service.Rukuguanli_tiaoweiliaoService();
            bean = service.rukuguanli_tiaoweiliao_ServiceSelect();
            //初始化原材料品名
            this.dataGridView_ruku_tiaoweiliao.Rows.Clear();
            if (this.dataGridView_ruku_tiaoweiliao.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.dataGridView_ruku_tiaoweiliao.Rows.Add();
                }
                this.dateTimePicker_tiaoweiliao_daohuo.Value = DateTime.Now;
                this.dateTimePicker_tiaoweiliao_yanshou.Value = DateTime.Now;
                this.tb_tiaoweiliao_no.Text = "";
                this.tb_tiaoweiliao_fahuodanwei.Text = "";
            }
        }
        //辅料初始化
        private void ruku_fuliao_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            rukustyle = 2;//调味料
            Bean.Rukuguanli_fuliaoBean bean = new FWMS.Bean.Rukuguanli_fuliaoBean();
            Service.Rukuguanli_fuliaoService service = new FWMS.Service.Rukuguanli_fuliaoService();
            bean = service.rukuguanli_fuliao_ServiceSelect();
            //初始化原材料品名
            this.dataGridView_ruku_fuliao.Rows.Clear();
            if (this.dataGridView_ruku_fuliao.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.dataGridView_ruku_fuliao.Rows.Add();
                }
                this.dateTimePicker_fuliao_daohuo.Value = DateTime.Now;
                this.dateTimePicker_fuliao_yanshou.Value = DateTime.Now;
                this.tb_fuliao_no.Text = "";
                this.tb_fuliao_fahuodanwei.Text = "";
            }

        }
        //产品初始化
        private void ruku_chanpin_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            rukustyle = 3;//调味料
            Bean.Rukuguanli_chanpinBean bean = new FWMS.Bean.Rukuguanli_chanpinBean();
            Service.Rukuguanli_chanpinService service = new FWMS.Service.Rukuguanli_chanpinService();
            bean = service.rukuguanli_chanpin_ServiceSelect();
            //初始化原材料品名
            this.dataGridView_ruku_chanpin.Rows.Clear();
            if (this.dataGridView_ruku_chanpin.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.dataGridView_ruku_chanpin.Rows.Add();
                }
                this.dateTimePicker_chanpin_yanshoudate.Value = DateTime.Now;
                this.TimePicker_chanpin_daohuo.Value = DateTime.Now;
            }

        }
        //新建表单按键按下
        private void btn_addForm_Click(object sender, EventArgs e)
        {
            switch (rukustyle)
            {
                case 0: ruku_yuancailiao_init(); break;
                case 1: ruku_tiaoweiliao_init(); break;
                case 2: ruku_fuliao_init(); break;
                case 3: ruku_chanpin_init(); break;
                default: break;
            }
        }
        //品名相同CHECK
        private bool pinming_same_check(string pinming, int nowsite)
        {

            switch (rukustyle)
            {
                case 0:
                    for (int i = nowsite + 1; i < this.dataGridView_yuanliaoinfo.Rows.Count; i++)
                    {
                        if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {
                            if (pinming.Equals(this.dataGridView_yuanliaoinfo.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.dataGridView_yuanliaoinfo.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.dataGridView_yuanliaoinfo.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.dataGridView_yuanliaoinfo.Rows[i].Cells[1].Value == null)
                                {
                                    this.dataGridView_yuanliaoinfo.Rows[i].Cells[1].Value = "";
                                }
                                if (this.dataGridView_yuanliaoinfo.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.dataGridView_yuanliaoinfo.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    this.dataGridView_yuanliaoinfo.Rows[nowsite].DefaultCellStyle.BackColor = Color.LightPink;
                                    this.dataGridView_yuanliaoinfo.Rows[i].DefaultCellStyle.BackColor = Color.LightPink;
                                    return false;
                                }
                            }
                        }
                    }
                    break;
                case 1:
                    for (int i = nowsite + 1; i < this.dataGridView_ruku_tiaoweiliao.Rows.Count; i++)
                    {
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {

                            if (pinming.Equals(this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.dataGridView_ruku_tiaoweiliao.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.dataGridView_ruku_tiaoweiliao.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[1].Value == null)
                                {
                                    this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[1].Value = "";
                                }
                                if (this.dataGridView_ruku_tiaoweiliao.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.dataGridView_ruku_tiaoweiliao.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    this.dataGridView_ruku_tiaoweiliao.Rows[nowsite].DefaultCellStyle.BackColor = Color.LightPink;
                                    this.dataGridView_ruku_tiaoweiliao.Rows[i].DefaultCellStyle.BackColor = Color.LightPink;
                                    return false;
                                }
                            }
                        }
                    }
                    break;
                case 2:
                    for (int i = nowsite + 1; i < this.dataGridView_ruku_fuliao.Rows.Count; i++)
                    {
                        if (this.dataGridView_ruku_fuliao.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {
                            if (pinming.Equals(this.dataGridView_ruku_fuliao.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.dataGridView_ruku_fuliao.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.dataGridView_ruku_fuliao.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.dataGridView_ruku_fuliao.Rows[i].Cells[1].Value == null)
                                {
                                    this.dataGridView_ruku_fuliao.Rows[i].Cells[1].Value = "";
                                }
                                if (this.dataGridView_ruku_fuliao.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.dataGridView_ruku_fuliao.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    this.dataGridView_ruku_fuliao.Rows[nowsite].DefaultCellStyle.BackColor = Color.LightPink;
                                    this.dataGridView_ruku_fuliao.Rows[i].DefaultCellStyle.BackColor = Color.LightPink;
                                    return false;
                                }
                            }
                        }
                    }
                    break;
                case 3:
                    for (int i = nowsite + 1; i < this.dataGridView_ruku_chanpin.Rows.Count; i++)
                    {
                        if (this.dataGridView_ruku_chanpin.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {
                            if (pinming.Equals(this.dataGridView_ruku_chanpin.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.dataGridView_ruku_chanpin.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.dataGridView_ruku_chanpin.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.dataGridView_ruku_chanpin.Rows[i].Cells[1].Value == null)
                                {
                                    this.dataGridView_ruku_chanpin.Rows[i].Cells[1].Value = "";
                                }
                                if (this.dataGridView_ruku_chanpin.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.dataGridView_ruku_chanpin.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    this.dataGridView_ruku_chanpin.Rows[nowsite].DefaultCellStyle.BackColor = Color.LightPink;
                                    this.dataGridView_ruku_chanpin.Rows[i].DefaultCellStyle.BackColor = Color.LightPink;
                                    return false;
                                }
                            }
                        }
                    }
                    break;
                default: break;
            }
            return true;
        }
        private void period_search_Click(object sender, EventArgs e)
        {
            COMMAND.CommandBean.cailiaostyle = rukustyle;
            Form_ruku_dateselect dateselect = new Form_ruku_dateselect();
            dateselect.ShowDialog();

            if (rukustyle == 3)
            {
                if (COMMAND.CommandBean.yanshoudate == null)
                {
                    return;
                }
                if (COMMAND.CommandBean.rukuyuancailiaoresult == null)
                {
                    this.dataGridView_ruku_chanpin.Rows.Clear();
                    Service.Rukuguanli_chanpinService chanpinservice = new FWMS.Service.Rukuguanli_chanpinService();
                    Bean.Rukuguanli_chanpinBean chanpin = new FWMS.Bean.Rukuguanli_chanpinBean();
                    chanpin.Ruku_daohuo = COMMAND.CommandBean.daohuodate.ToString().Trim();
                    chanpin.Ruku_yanshou = COMMAND.CommandBean.yanshoudate.ToString().Trim();
                    chanpin = chanpinservice.rukuguanli_chanpindate_ServiceSelectContation(chanpin);
                    datagridviewadddata(chanpin);
                }
                else
                {
                    Bean.Rukuguanli_chanpinBean chanpinselectall = new FWMS.Bean.Rukuguanli_chanpinBean();
                    chanpinselectall.Selectresult = COMMAND.CommandBean.rukuyuancailiaoresult;
                    datagridviewadddata(chanpinselectall);
                }
            }
            else
            {
                if (COMMAND.CommandBean.no == null)
                {
                    return;
                }
                this.tst_no.Text = COMMAND.CommandBean.no.ToString();
                this.dataGridView_ruku_chanpin.Rows.Clear();
                noselect();
            }

        }

        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.dataGridView_ruku_tiaoweiliao.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }

        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.dataGridView_ruku_tiaoweiliao.CurrentCell == null)
                return;
            int insertRowIndex = this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_ruku_tiaoweiliao.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_ruku_tiaoweiliao.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_tiaoweiliao.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单重只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }
                    //重新计算重量（实收数）
                    if (this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[3].Value != null
                        && this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[4].Value != null
                        && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[3].Value)
                        && !"".Equals(this.dataGridView_ruku_tiaoweiliao.Rows[this.dataGridView_ruku_tiaoweiliao.CurrentCell.RowIndex].Cells[4].Value))
                    {

                        this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[5].Value = Convert.ToString(float.Parse(this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[3].Value.ToString()) * Convert.ToInt32(this.dataGridView_ruku_tiaoweiliao.Rows[insertRowIndex].Cells[4].Value));
                    }



                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.dataGridView_ruku_fuliao.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.dataGridView_ruku_fuliao.CurrentCell == null)
                return;
            int insertRowIndex = this.dataGridView_ruku_fuliao.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_ruku_fuliao.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_ruku_fuliao.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_fuliao.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.dataGridView_ruku_fuliao.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单重只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }
                    //重新计算重量（实收数）
                    if (this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[3].Value != null
                        && this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[4].Value != null
                        && !"".Equals(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[3].Value)
                        && !"".Equals(this.dataGridView_ruku_fuliao.Rows[this.dataGridView_ruku_fuliao.CurrentCell.RowIndex].Cells[4].Value))
                    {

                        this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[5].Value = Convert.ToString(float.Parse(this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[3].Value.ToString()) * Convert.ToInt32(this.dataGridView_ruku_fuliao.Rows[insertRowIndex].Cells[4].Value));
                    }



                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }
        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.dataGridView_ruku_chanpin.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }

        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.dataGridView_ruku_chanpin.CurrentCell == null)
                return;
            int insertRowIndex = this.dataGridView_ruku_chanpin.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.dataGridView_ruku_chanpin.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.dataGridView_ruku_chanpin.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_chanpin.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.dataGridView_ruku_chanpin.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单重只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }
                    //重新计算重量（实收数）
                    if (this.dataGridView_ruku_chanpin.Rows[this.dataGridView_ruku_chanpin.CurrentCell.RowIndex].Cells[3].Value != null
                        && this.dataGridView_ruku_chanpin.Rows[this.dataGridView_ruku_chanpin.CurrentCell.RowIndex].Cells[4].Value != null
                        && !"".Equals(this.dataGridView_ruku_chanpin.Rows[this.dataGridView_ruku_chanpin.CurrentCell.RowIndex].Cells[3].Value)
                        && !"".Equals(this.dataGridView_ruku_chanpin.Rows[this.dataGridView_ruku_chanpin.CurrentCell.RowIndex].Cells[4].Value))
                    {

                        this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[5].Value = Convert.ToString(float.Parse(this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[3].Value.ToString()) * Convert.ToInt32(this.dataGridView_ruku_chanpin.Rows[insertRowIndex].Cells[4].Value));
                    }



                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        //当前入库时间和库存保存时间进行比较
        private bool comsavedate(string date, string type)
        {
            Service.Rukuguanli_yuancailiaoService service = new FWMS.Service.Rukuguanli_yuancailiaoService();
            string maxdate = service.rukuguanli_getkucunmaxdate(type);
            if (maxdate == null || "".Equals(maxdate))
            {
                return true;
            }
            else
            {
                if (int.Parse(date) <= int.Parse(maxdate))
                {
                    MessageBox.Show("当前验收日期已经集计结束，不能在当前验收日期或之前进行入库操作", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }

        private void tiaoliao_DelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.dataGridView_ruku_tiaoweiliao.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                if (cell.ColumnIndex == 3 || cell.ColumnIndex == 4)
                {
                    this.dataGridView_ruku_tiaoweiliao.Rows[cell.RowIndex].Cells[5].Value = null;
                }
                cell.Value = null;
            }
        }

        private void fuliao_DelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.dataGridView_ruku_fuliao.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                if (cell.ColumnIndex == 3 || cell.ColumnIndex == 4)
                {
                    this.dataGridView_ruku_fuliao.Rows[cell.RowIndex].Cells[5].Value = null;
                }
                cell.Value = null;
            }
        }

        private void chengpin_DelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.dataGridView_ruku_chanpin.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                cell.Value = null;
            }
        }

        private void dateTimePicker_chanpin_daohuo_ValueChanged(object sender, EventArgs e)
        {

        }

        private void dataGridView_yuanliaoinfo_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.dataGridView_yuanliaoinfo.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

        private void dataGridView_ruku_tiaoweiliao_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.dataGridView_ruku_tiaoweiliao.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

        private void dataGridView_ruku_fuliao_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.dataGridView_ruku_fuliao.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

        private void dataGridView_ruku_chanpin_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.dataGridView_ruku_chanpin.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

    }

}
